package com.kitty.game.role.service;

import com.alibaba.fastjson.JSON;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.ServerService;
import com.kitty.game.player.model.PlayerProfile;
import org.nutz.http.Request;
import org.nutz.http.Sender;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Dubbo 查询全服已有角色的
 */
@Service
public class GateService {

    /**
     * 添加角色
     */
    public void addRoleToDist(String sid, PlayerProfile playerProfile) {
        Map<String, Object> params = new HashMap<>();
        params.put("sid", sid);
        params.put("content", JSON.toJSONString(playerProfile));
        try {
            Request request = Request.create(SpringUtils.getBean(ServerService.class).getLoginServerUrl() + "/game/addRole", Request.METHOD.POST).setParams(params);
            Sender.create(request).setTimeout(1000).send();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
